package cn.kgc.changjian.service;

import cn.kgc.changjian.mapper.FaqsMapper;
import cn.kgc.changjian.pojo.Faqs;
import cn.kgc.changjian.pojo.FaqsExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-05-25 20:22
 */
@Service
public class FaqsServiceImpl implements cn.kgc.changjian.service.FaqsService {
    @Resource
    FaqsMapper faqsMapper;

    @Override
    public PageInfo<Faqs> selectPageInfo(Integer pageNum, Integer pageSize, Integer classId) {
        PageHelper.startPage(pageNum,pageSize);

        FaqsExample example=new FaqsExample();
        FaqsExample.Criteria criteria = example.createCriteria();

        if(classId==0){
            List<Faqs> faqs = faqsMapper.selectByExample(null);
            PageInfo<Faqs> pageInfo=new PageInfo<>(faqs);
            return pageInfo;
        }else{
            criteria.andClassidEqualTo(classId);
            List<Faqs> faqs = faqsMapper.selectByExample(example);
            PageInfo<Faqs> pageInfo=new PageInfo<>(faqs);
            return pageInfo;
        }
    }

    @Override
    public Integer add(Faqs faqs) {
        return faqsMapper.insert(faqs);
    }

    @Override
    public Integer delete(Integer id) {
        return faqsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Faqs selectById(Integer id) {
        return faqsMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer update(Faqs faqs) {
        return faqsMapper.updateByPrimaryKeySelective(faqs);
    }
}
